package com.wjh.base;


import com.wjh.bean.Constants;
import com.wjh.bean.Result;
import com.wjh.enums.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2017/5/25.
 */
@Component
public class BaseController {
    @Autowired
    protected BaseRedisService baseRedisService;

    public static Result success(Object o){
        Result result = new Result();
        result.setCode(Constants.HTTP_RES_CODE_200);
        result.setMsg(Constants.HTTP_RES_CODE_200_VALUE);
        result.setData(o);
        return result;
    }
    public static Result success(String msg){
        Result result = new Result();
        result.setCode(Constants.HTTP_RES_CODE_200);
        result.setMsg(msg);
        return result;
    }

    public static Result error(String msg){
        Result result = new Result();
        result.setCode(Constants.HTTP_RES_CODE_500);
        result.setMsg(msg);
        return result;
    }

    public static Result success(ResultEnum anEnum, Object o){
        Result result = new Result();
        result.setCode(anEnum.getCode());
        result.setMsg(anEnum.getMsg());
        result.setData(o);
        return result;
    }
    public static Result success(){
        return success(null);
    }
    public static Result error(Integer code, String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static Result error(ResultEnum anEnum){
        Result result = new Result();
        result.setCode(anEnum.getCode());
        result.setMsg(anEnum.getMsg());
        return result;
    }
}
